﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Linq;
namespace WPFExcelReport
{
    public partial class TEKWB
    {

        #region ==IsTemp===========
        public static readonly DependencyProperty IsTempProperty = DependencyProperty.Register("IsTemp",
            typeof(bool), typeof(TEKWB),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsTempChanged));
        public bool IsTemp
        {
            get
            {
                return (bool)GetValue(IsTempProperty);
            }
            set
            {
                SetValue(IsTempProperty, value);
            }
        }
        private static void OnIsTempChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TEKWB;
            if (src != null)
            {
                src.IsTemp = (bool)e.NewValue;
            }
        }
        #endregion

        public TEKWB()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VICC_WBBEW();
            this.DataContext = MV;
            InitializeComponent();
        }

        public override void LOADBYAUF()
        {
            TBMain.Clear();
            if (ORDERNUM.Length < 11)
                return;
            if (!IsShowEKGB)
                return; 
            KRS = ORDERNUM.Substring(1, 2);
            LFD = ORDERNUM.Substring(3, 6);
            POS = ORDERNUM.Substring(6, 3);
            PM["ORDERNUM"] = ORDERNUM;
            PM["AUFTYP"] = ORDERNUM.Substring(0, 1);
            PM["KRS"] = ORDERNUM.Substring(1, 2);
            PM["LFD"] = ORDERNUM.Substring(3, 6);
            PM["POS"] = ORDERNUM.Substring(9, 3);
            switch (ORDERNUM.Substring(0, 1))
            {
                case "B": 
                    SResult = ((VICC_WBBEW)MV).LOADBYEK(PM);
                    MergeData(SResult, true, true);
                    if (TBMain.Rows.Count > 0)
                        return;
                    SResult = ((VICC_WBBEW)MV).VWBBEW.LOADBYEK(PM);
                    SResult.Tables[0].TableName = MV.TableName;
                    MergeData(SResult, true, true);
                    IsTemp = false;
                    break;
            }
            base.LOADBYAUF();
        }
        public override void OnShowEKGBChg(bool value)
        {
            if (!value)
                return;
            LOADBYAUF();
            base.OnShowEKGBChg(value);
        }
    }
}
